From: Jason Rumney Date: Wed, 27 Aug 2003 22:57:54 +0000 (+0000) Subject: (sys_pipe): Protect against file descriptor overflow. X-Git-Tag: archive/raspbian/1%29.2+1-2+rpi1~1^2~25701 X-Git-Url: https://dgit.raspbian.org/%22http:/www.example.com/cgi/%22https:/www.github.com/%22bookmarks:///%22http:/www.example.com/cgi/%22https:/www.github.com/%22bookmarks:/?a=commitdiff_plain;h=8d8c3dd91ead5fbcd9c96b49861d7cb4bc03c0b5;p=emacs.git (sys_pipe): Protect against file descriptor overflow. --- diff --git a/src/w32.c b/src/w32.c index 744cc593133..f9739999478 100644 --- a/src/w32.c +++ b/src/w32.c @@ -3450,11 +3450,22 @@ sys_pipe (int * phandles) if (rc == 0) { - flags = FILE_PIPE | FILE_READ | FILE_BINARY; - fd_info[phandles[0]].flags = flags; + /* Protect against overflow, since Windows can open more handles than + our fd_info array has room for. */ + if (phandles[0] >= MAXDESC || phandles[1] >= MAXDESC) + { + _close (phandles[0]); + _close (phandles[1]); + rc = -1; + } + else + { + flags = FILE_PIPE | FILE_READ | FILE_BINARY; + fd_info[phandles[0]].flags = flags; - flags = FILE_PIPE | FILE_WRITE | FILE_BINARY; - fd_info[phandles[1]].flags = flags; + flags = FILE_PIPE | FILE_WRITE | FILE_BINARY; + fd_info[phandles[1]].flags = flags; + } } return rc;